<?php
require_once 'BaseController.php';
class Admin_GuideController extends BaseController
{
    public function init()
    {
        $this->view->module = $this->_request->getModuleName();
        $this->view->controller = $this->_request->getControllerName();
        $this->view->action = $this->_request->getActionName();

        Zend_Loader::loadClass('AuthModel');
        Zend_Loader::loadClass('AdminModel');
        Zend_Loader::loadClass('GuideModel');
        
        $this->_arrParam = $this->_request->getParams();
		
		//Bo di cac truong ko can thiet
		unset($this->_arrParam['module']);
		unset($this->_arrParam['controller']);
		unset($this->_arrParam['action']);
    }
    public function indexAction(){
        $GModel = new GuideModel();
        if ($this->_request->isPost()) {
            $text = $this->_request->getParam('text');
            $text = stripslashes($text);
            $GModel->update(array("text" => $text), array("id=?" => 1));
            
            $this->_redirect('/admin/guide/index');
        }else{
            $data = $GModel->fetchRow("id = '1'");
            $this->view->arrParam = $data;
        }
    }
    public function contactAction(){
        $GModel = new GuideModel();
        if ($this->_request->isPost()) {
            $text = $this->_request->getParam('text');
            $text = stripslashes($text);
            $row = $GModel->fetchRow("id = '2'");
            if($row)
                $GModel->update(array("text" => $text), array("id=?" => 2));
            else 
                $GModel->insert(array("text" => $text,"id" => "2"));
            
            $this->_redirect('/admin/guide/contact');
        }else{
            $data = $GModel->fetchRow("id = '2'");
            $this->view->arrParam = $data;
        }
    }
    public function policyAction(){
        $GModel = new GuideModel();
        if ($this->_request->isPost()) {
            $text = $this->_request->getParam('text');
            $text = stripslashes($text);
            $row = $GModel->fetchRow("id = '3'");
            if($row)
                $GModel->update(array("text" => $text), array("id=?" => 3));
            else 
                $GModel->insert(array("text" => $text,"id" => "3"));
            
            $this->_redirect('/admin/guide/policy');
        }else{
            $data = $GModel->fetchRow("id = '3'");
            $this->view->arrParam = $data;
        }
    }
}
?>